using System;
using System.Data;
using System.Collections;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.PostCode
{
    public class PostCodeDB
    {
        public PostCodeDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public PostCode GetPostCode(string PostCodeString)
        {
            MyDatabase _Db = new MyDatabase();
            string _spName = "sprocPostCodeSelectSingleItemByPostCode";
            PostCode _result = null;
            DataTable _dt;
            SortedList _sPara = new SortedList();

            _sPara.Add("@PostCode", PostCodeString);

            _dt = _Db.GetDataTableBySP(_spName, _sPara);

            if (_dt != null && _dt.Rows.Count > 0)
            {
                _result = new PostCode();
                _result = FillDataRecord(_dt);
            }

            return _result;
        }

        public Int64 Insert(PostCode postcode)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocPostCodeInsertUpdateSingleItem]";
            
            SortedList _sPara = new SortedList();
            
            #region Parameter
                _sPara.Add("PostCodeId", postcode.PostCodeId);
                _sPara.Add("PostCode", postcode.PostCodeString);
                _sPara.Add("Type", postcode.Type);
                _sPara.Add("BlockNo", postcode.BlockNo);
                _sPara.Add("UnitNo", postcode.UnitNo);
                _sPara.Add("StreetName", postcode.StreetName);
                _sPara.Add("BuildingName", postcode.BuildingName);
                _sPara.Add("Latitude", postcode.Latitude);
                _sPara.Add("Longtitude", postcode.Longtitude);
                _sPara.Add("Zone", postcode.Zone);
                _sPara.Add("Status", postcode.Status );
                _sPara.Add("RefCEUserId", postcode.RefCEUserId);
                //_sPara.Add("@Info1", template.Info1);
                //_sPara.Add("@Info2", template.Info2);
                //_sPara.Add("@Info3", template.Info3);
                //_sPara.Add("@Info4", template.Info4);
                //_sPara.Add("@Info5", template.Info5);
                //_sPara.Add("@Info6", template.Info6);
                //_sPara.Add("@Info7", template.Info7);
                //_sPara.Add("@Info8", template.Info8);
                //_sPara.Add("@Info9", template.Info9);
                //_sPara.Add("@Info10", template.Info10);
                //_sPara.Add("@Info11", template.Info11);
                //_sPara.Add("@Info12", template.Info12);
                //_sPara.Add("@Info13", template.Info13);
                //_sPara.Add("@Info14", template.Info14);
                //_sPara.Add("@Info15", template.Info15);
                //_sPara.Add("@Info16", template.Info16);
                //_sPara.Add("@Info17", template.Info17);
                //_sPara.Add("@Info18", template.Info18);
                //_sPara.Add("@Info19", template.Info19);
                //_sPara.Add("@Info20", template.Info20);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        private PostCode FillDataRecord(DataTable myDataTable)
        {
            PostCode myPostCode = new PostCode();
            myPostCode.PostCodeId = Convert.ToInt32(myDataTable.Rows[0]["PostCodeId"].ToString());
            myPostCode.PostCodeString = myDataTable.Rows[0]["PostCode"].ToString();
            myPostCode.Type = Convert.ToChar(myDataTable.Rows[0]["Type"].ToString());
            myPostCode.BlockNo = myDataTable.Rows[0]["BlockNo"].ToString();
            myPostCode.UnitNo = myDataTable.Rows[0]["UnitNo"].ToString();
            myPostCode.StreetName = myDataTable.Rows[0]["StreetName"].ToString();
            myPostCode.BuildingName = myDataTable.Rows[0]["BuildingName"].ToString();
            //myPostCode.Latitude = myDataTable.Rows[0]["Latitude"].ToString();
            //myPostCode.Longtitude = myDataTable.Rows[0]["Longtitude"].ToString();
            //myPostCode.Zone = myDataTable.Rows[0]["Zone"].ToString();
            //myPostCode.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());
            //myPostCode.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            
            return myPostCode;
        }
        
    }
}